import type { AppRouteRecordRaw } from '@/types/system'

// 常量路由 - 不需要权限验证的路由
export const constantRoutes: AppRouteRecordRaw[] = [
  {
    path: '/redirect',
    component: () => import('@/layouts/Layout.vue'),
    meta: { hidden: true, title: '重定向' },
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    meta: { 
      hidden: true,
      title: '登录'
    }
  },
  {
    path: '/register',
    component: () => import('@/views/register/index.vue'),
    meta: { 
      hidden: true,
      title: '注册'
    }
  },
  {
    path: '/404',
    component: () => import('@/views/error/404.vue'),
    meta: { 
      hidden: true,
      title: '页面不存在'
    }
  },
  {
    path: '/401',
    component: () => import('@/views/error/401.vue'),
    meta: { 
      hidden: true,
      title: '无权限访问'
    }
  },
  {
    path: '/500',
    component: () => import('@/views/error/500.vue'),
    meta: { 
      hidden: true,
      title: '服务器错误'
    }
  },
  {
    path: '/share/:code',
    name: 'PublicShareAccess',
    component: () => import('@/views/share/Access.vue'),
    meta: { hidden: true, title: '文件分享' }
  },
  {
    path: '/',
    redirect: '/dashboard',
    component: () => import('@/layouts/Layout.vue'),
    meta: {
      title: '首页',
      icon: 'HomeFilled'
    },
    children: [
      {
        path: 'dashboard',  // ✅ 改为相对路径
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: {
          title: '仪表板',
          icon: 'Monitor',
          affix: true,
          noCache: false
        }
      }
    ]
  },
  {
    path: '/profile',
    component: () => import('@/layouts/Layout.vue'),
    meta: { hidden: true, title: '个人中心' },
    children: [
      {
        path: 'index',  // ✅ 改为相对路径
        name: 'Profile',
        component: () => import('@/views/profile/index.vue'),
        meta: {
          title: '个人中心',
          icon: 'User',
          noCache: true
        }
      }
    ]
  }
]

// 路由守卫相关
export const whiteList = ['/login', '/register', '/verify-email', '/404', '/401', '/500'] // 白名单路由

// 导出一个通用 404 兜底路由，供动态挂载后作为最后一道防线
export const catchAllNotFoundRoute: AppRouteRecordRaw = {
  path: '/:pathMatch(.*)*',
  name: 'NotFound',
  component: () => import('@/views/error/404.vue'),
  meta: { hidden: true, title: '页面不存在' }
}